/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.List;
import queenb.net.entitybean.M200;
import queenb.web.store.M200Store;
import queenb.web.util.Util;

/**
 *
 * @author DUYNGUYEN
 */
public class M200Controller extends QueenbController {
    private int pm200;
    private String mv201;
    private String mv202;
    private Boolean mn206;
    private M200Store store;
    
    public M200Controller(){
        store = new M200Store();
        Object action = getRequest().getParameter("action");
        Object pm200Object = getRequest().getParameter("pm200");
        if(action != null)
        {
            if(action.equals("edit"))
            {
                this.pm200 = Util.parseInt(pm200Object);
                getDetailEditM200(pm200);
            }
        }
    }
    
    public void getDetailEditM200(int id) {
        try {
            List<M200> listM200Edit = getListAllM200();
            if (listM200Edit.size() > 0) {
                for (int i = 0; i < listM200Edit.size(); i++) {
                    if (listM200Edit.get(i).getPm200() == id) {
                        this.mv201 = (listM200Edit.get(i).getMv201());
                        this.mv202 = (listM200Edit.get(i).getMv202());
                        System.out.println(getMn206());
                        this.mn206 =  listM200Edit.get(i).getMn206()==1? true: false;
                        System.out.println("D: - mn206: "+ mn206);
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error when getDetailEditN850. ERROR CODE: " + ex.getMessage());
        }
    }
    public List<M200> getListAllM200() {

        try {
            System.out.println(getLogin().getModule()+ " , " + getLogin().getCompanyNo()+" , " + getLogin().getId()+ " , " +getLogin().getUserName());
            List<M200> list = store.getListM200All(getLogin().getModule(), getLogin().getCompanyNo(),getLogin().getId(), getLogin().getUserName());
            return list;
        } catch (Exception ex) {
            System.out.println("D:- error from getListAllM200: "+ex);
            return null;
        }

    }
    public void updateM200(){
        try {
            System.out.println("D:- getPm200(): "+ getPm200() +"");
            int vmn206=0;
            int vpk100 = getLogin().getId();
            if(mn206){
                vmn206 = 1;
                vpk100= getLogin().getCompanyNo();
            }
            System.out.println("D:--   vmn206: "+ vmn206);
            System.out.println("D:--   vpk100: "+ vpk100);
            System.out.println("store.updateM200("+ getPm200()+" , "+ getLogin().getModule()+" , "+  getLogin().getCompanyNo()+" , "+ vpk100+" , "+  getMv201()+" , "+  " ------ "+" , "+  null+" , "+  null+" , "+  0+" , "+  vmn206+" , "+ null+" , "+ getLogin().getUserName());
            int count = store.updateM200(getPm200(), getLogin().getModule(), getLogin().getCompanyNo(), vpk100, getMv201(), getMv202(), null, null, 0, vmn206, null, getLogin().getUserName());
             if (count > 0) {
                showGlobalReport(true, getResourceString("success"));
            } else {
                showGlobalReport(true, getResourceString("error"));
            }
       
        
        sendRedirectUrlTab("setting.jsp?tab=header21&lilnkM200="+Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
        }
    }

    /**
     * @return the pm200
     */
    public int getPm200() {
        return pm200;
    }

    /**
     * @param pm200 the pm200 to set
     */
    public void setPm200(int pm200) {
        this.pm200 = pm200;
    }

    /**
     * @return the mv201
     */
    public String getMv201() {
        return mv201;
    }

    /**
     * @param mv201 the mv201 to set
     */
    public void setMv201(String mv201) {
        this.mv201 = mv201;
    }

    /**
     * @return the mv202
     */
    public String getMv202() {
        return mv202;
    }

    /**
     * @param mv202 the mv202 to set
     */
    public void setMv202(String mv202) {
        this.mv202 = mv202;
    }

    /**
     * @return the mn206
     */
    public Boolean getMn206() {
        return mn206;
    }

    /**
     * @param mn206 the mn206 to set
     */
    public void setMn206(Boolean mn206) {
        this.mn206 = mn206;
    }
}
